# -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait # available since 2.4.0
from selenium.webdriver.support import expected_conditions as EC # available since 2.26.0
from selenium.webdriver.common.action_chains import ActionChains
import unittest
import random
import time
from cookies import lasthopes, randomword
import re
import string
import sys
from selenium.webdriver.common.keys import Keys
from PIL import Image
from os import remove, listdir, sep
from os.path import basename, isfile
import tempfile
from warnings import warn
from basecart import BaseCart

class cart_oc_empty(BaseCart):
    def test_cart_oc_empty(self):
        driver = self.driver
        #Link to cart
        cartbut = driver.find_element_by_css_selector("div.b-header-top-cell-h > span.b-header-top-cell-anchor")
        cartbut.click()
        #Empty cart popup
        cart_pop = [p for p in WebDriverWait(driver, timeout=6).until(lambda dr: dr\
                                        .find_elements_by_css_selector("div.b-popup-h"))\
                                    if p.find_element_by_css_selector("div.b-popup-emptycart")][0]
        assert u'Чтобы добавить товары в корзину' in cart_pop.text
        #Close popup
        close_btn = cart_pop.find_element_by_css_selector("div.b-popup-close")
        close_btn.click()
        #Wait for popup dissapeared
        WebDriverWait(driver, timeout=4)\
                   .until(lambda dr: not self.check_exists(cart_pop))
        #Revive popup
        cartbut.click()
        time.sleep(1) #Wait for popup renewed
        cart_pop = WebDriverWait(driver, timeout=4)\
                   .until(lambda dr: [p for p in dr.find_elements_by_css_selector("div.b-popup-h")\
                                      if p.find_element_by_css_selector("div.b-popup-emptycart")])[0]
        #Wait for popup self-closed
        WebDriverWait(driver, timeout=10)\
                   .until(lambda dr: not self.check_exists(cart_pop))
